const Service = require('egg').Service;
class myService extends Service {
  async getuser(uid) {
    const sql=`SELECT * FROM user where id=${uid}`
    const data = await this.app.mysql.query(sql);
    return data;
  }
  async getopus(uid){
    const sql=`SELECT * FROM opus LEFT JOIN opus1user ON opus1user.opusid = opus.id  WHERE opus1user.userid=${uid} `
    const data = await this.app.mysql.query(sql);
    return data;
  }
  async getcook(uid){
    const sql=`SELECT * FROM cook LEFT JOIN cook1user ON cook1user.cookid = cook.id  WHERE cook1user.userid=${uid} `
    const data = await this.app.mysql.query(sql);
    return data;
  }
  async getfollow(uid){
    const sql=`SELECT *  FROM follow  LEFT JOIN user ON user.id=follow.fans WHERE follow.star=${uid}`
    const data = await this.app.mysql.query(sql);
    return data;
  }
  async getfollow2(uid){
    const sql=`SELECT * FROM follow  LEFT JOIN user ON user.id=follow.star WHERE follow.fans=${uid}`
    const data = await this.app.mysql.query(sql);
    return data;
  }
  async getfollow3(fans,star){
    const sql=`SELECT follow.id FROM follow LEFT JOIN user on follow.fans=user.id WHERE follow.star=${fans} AND user.email=${star}`
    const data = await this.app.mysql.query(sql);
    return data;
  }
  async guanzhu1(fans,star){
    const sql=`INSERT INTO follow (star,fans) VALUES (${fans},(SELECT id FROM user WHERE email=${star}))`
    const data = await this.app.mysql.query(sql);
    return data;
  }
  async guanzhu2(fans,star){
    const sql=`DELETE FROM follow WHERE fans=(SELECT id FROM user WHERE email=${star}) AND star=${fans}`
    const data = await this.app.mysql.query(sql);
    return data;
  }
}
module.exports = myService;